import * as MarkdownIt from 'markdown-it';
import {HighlightUtils} from "./HighlightUtils";

export class MarkdownUtils {

  private static mdRender: MarkdownIt = null;

  // /*
  // * render markdown to html
  // * */
  public static render(md: string): string {
    if (!MarkdownUtils.mdRender) {
      MarkdownUtils.mdRender = new MarkdownIt({
        html: true,
        xhtmlOut: true,
        highlight: (content, lang) => {
          return HighlightUtils.highlight(content);
        }
      })
        .set({
          breaks: true
        });
    }
    return MarkdownUtils.mdRender.render(md);
  }
}
